package com.baosight.sczx.zm.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.baosight.iplat4j.core.ei.EiBlockMeta;
import com.baosight.iplat4j.core.ei.EiColumn;
import com.baosight.iplat4j.core.ei.EiInfo;
import com.baosight.iplat4j.ep.ServiceEPBase;
import com.baosight.sczx.common.zm.basetools.StaticTools;

/**
 * 三违部门统计
 * <p>Title: ServiceZM9H.java</p>
 * <p>Description: </p>
 * <p>Copyright: Baosight Software LTD.co Copyright (c) 2002</p>
 * <p>Company: Baosight Software</p>
 * @author 郭淑芳
 * @version 1.0
 * <pre>Histroy:
 *          2012-12-18 上午05:37:27  郭淑芳  Create
 *</pre>
 */
public class ServiceZM9I extends ServiceEPBase {

	/**
	 * 初始化
	 * <p>Function: initLoad</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZM9H</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2012-12-18上午05:37:02 郭淑芳
	 * </p>
	 *
	 */
	@Override
	public EiInfo initLoad(EiInfo inInfo) {
		return query(inInfo);
	}

	/**
	 * 三违部门分布查询
	 * <p>Function: query</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZM9H</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2012-12-18上午05:37:13 郭淑芳
	 * </p>
	 *
	 */
	@Override
	public EiInfo query(EiInfo inInfo) {
		List<Map> _list = new ArrayList();
		Map para = new HashMap();

		String fdCurrentDate = StaticTools.getDate(); // 当前日期
		String fdBeginDate = fdCurrentDate.substring(0, 8) + "01"; // 当月开始日期

		para.put("fdBeginDate", fdBeginDate);
		para.put("fdCurrentDate", fdCurrentDate);

		// 查询本月隐患个数排名前五的地点
		_list = dao.query("ZM9I.queryForTernateDept", para);

		// 取前五条记录
		int count = _list.size();
		count = count > (int) 5 ? (int) 5 : count;

		EiInfo outInfo = new EiInfo();
		outInfo.addBlock("result").addBlockMeta(getMeta());
		for (int i = (int) 0; i < count; i++) {
			outInfo.getBlock("result").addRow(_list.get(i));
		}
		return outInfo;
	}

	/**
	 * 构造列
	 * <p>Function: getMeta</p>
	 * <p>Description: </p>
	 * <p>return value:EiBlockMeta</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2012-12-18上午05:36:51 郭淑芳
	 * </p>
	 *
	 */
	private EiBlockMeta getMeta() {
		EiBlockMeta eiMetadata = new EiBlockMeta();
		EiColumn eiColumn = new EiColumn("item");
		eiColumn.setFieldLength(100);
		eiColumn.setDescName("三违部门");
		eiMetadata.addMeta(eiColumn);

		eiColumn = new EiColumn("value");
		eiColumn.setFieldLength(8);
		eiColumn.setDescName("三违个数");
		eiMetadata.addMeta(eiColumn);

		return eiMetadata;
	}
}
